<?php

namespace Home\Controller;
use Think\Controller;
// 指定允许其他域名访问  
header('Access-Control-Allow-Origin:*');  
// 响应类型  
header('Access-Control-Allow-Methods:*');  
// 响应头设置  
header('Access-Control-Allow-Headers:x-requested-with,content-type');  
class MessageController extends Controller
{
    
    public function lst()
    {
        if(!IS_POST)
        {
            datamsg(0,'非法操作');
        }

        $user_id=I('user_id');
        $token=I('token');

        $user=user_cinfo($user_id,$token);
        $list=D('article')->where('type_id=1')->select();

        
        
        if(empty($list))
        {
            datamsg('1','暂无更多');
        }

        foreach ($list as $key => $value) {
            $list[$key]['create_time']= date('Y-m-d',$value['create_time']);
            $list[$key]['content']    = htmlspecialchars_decode($value['content']);
        }
        
        if($user['status']!='2')
        {
           $status['status']='2';
           $resss= D('wxuser')->where('uid=1')->save($status);
        }


        datamsg('1','成功',$list);
    }

    //客服列表
    public function kefu_list()
    {
        if(!IS_POST)
        {
            datamsg(0,'非法操作');
        }
        $res=D('article')->field('id,title')->where('type_id=5')->select();
        if(empty($res))
        {
            datamsg('1','暂无更多数据');
        }
        datamsg('1','成功',$res);
    }

    //客服详情
    public function kefu_info()
    {
        if(!IS_POST)
        {
            datamsg(0,'非法操作');
        }
        $id=I('id');
        if(empty($id))
        {
            datamsg('0','请选择你要查看的文章');
        }
        $res=D('article')->where('id='.$id)->find();
        if(empty($res))
        {
            datamsg('1','暂无更多数据');
        }
        datamsg('1','成功',$res);
    }

    //反馈
    public function fankui()
    {
        if(!IS_POST)
        {
            datamsg(0,'非法操作');
        }
        
        $user_id=I('user_id');
        $token=I('token');

        $user=user_cinfo($user_id,$token);
        if(empty(I('content')))
        {
            datamsg('0','请填写反馈内容');
        }
        $data['user_id']=$user_id;
        $data['content']=I('content');

        $res=D('feedback')->add($data);
        if(empty($res))
        {
            datamsg('0','系统繁忙');
        }
        datamsg('1','成功',$res);
    }
    // public function qingkong()
    // {
    //     if(!IS_POST)
    //     {
    //         datamsg(0,'非法操作');
    //     }
    //     $user_id=I('user_id');
    //     $token=I('token');
    //     $user=user_cinfo($user_id,$token);

    //     $article=I('article_id');

    //     $logout['logout'][]=$user_id;
    //     var_dump($logout);die;
    //     foreach ($article as $key => $value){
    //         D('article')->where('id='.$value)->save();
    //     }

    //     $list=D('article')->where('type_id=1')->select();
    //     if(empty($list))
    //     {
    //         datamsg('1','暂无更多');
    //     }
    //     datamsg('1','成功',$list);
    // }

}
